package wql.aaa.service.impl;

import com.aaa.entity.TbBottomArticle;
import com.aaa.entity.TbLink;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import wql.aaa.service.TbLinkService;
import wql.aaa.dao.TbLinkMapper;
import org.springframework.stereotype.Service;
import wql.aaa.vo.LinkFormData;

import java.util.Date;
import java.util.List;

/**
* @author 咕噜咕噜
* @description 针对表【tb_link】的数据库操作Service实现
* @createDate 2023-02-28 16:47:32
*/
@Service
public class TbLinkServiceImpl extends ServiceImpl<TbLinkMapper, TbLink>
    implements TbLinkService{

    @Autowired
    private TbLinkMapper tbLinkMapper;
    @Override
    public Result queryAll(Integer currentPage, Integer pageSize, LinkFormData linkFormData) {

        PageHelper.startPage(currentPage,pageSize);
        List<TbLink> tbLinkList = tbLinkMapper.find(linkFormData);
        PageInfo<TbLink> info = new PageInfo<>(tbLinkList);

        return new Result(2000,"查询成功",info);
    }

    @Override
    public Result add(TbLink tbLink) {
        TbLink tbLink1 = new TbLink();
        tbLink1.setLinkName(tbLink.getLinkName());
        tbLink1.setLinkUrl(tbLink.getLinkUrl());
        Date date = new Date();
        tbLink1.setGmtCreate(date);
        tbLink1.setGmtModified(date);
        tbLink1.setIsDeleted(0);
        tbLink1.setIsDisable(0);
        int insert = tbLinkMapper.insert(tbLink1);

        if (insert>0){
            return new Result(2000,"添加成功");
        }else {
            return new Result(5000,"添加失败");
        }
    }

    @Override
    public Result change(String linkId, Integer isDisable) {
        tbLinkMapper.change(linkId, isDisable);
        return new Result(2000,"修改状态成功");
    }

    @Override
    public Result deleteByLinkId(String linkId) {
        int i = tbLinkMapper.deleteById(linkId);
        if (i>0){
            return new Result(2000,"添加成功");
        }else {
            return new Result(5000,"添加失败");
        }
    }

    @Override
    public Result updateLink(TbLink tbLink) {
        int i = tbLinkMapper.updateById(tbLink);
        if (i>0){
            return new Result(2000,"修改成功");
        }else {
            return new Result(5000,"修改失败");
        }
    }

}




